package edu.umd.ion.wavemeter.client;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Panel;

import edu.umd.ion.wavemeter.service.WavemeterChannelData;
import edu.umd.ion.wavemeter.service.WavemeterServiceAsync;

/**
 * Basic Channel oriented Sub-Widget implementing a cell in the table of wavelength results.
 * This class only implements the bookkeeping. The detail controls and
 * displays are implemented in derived classes.
 */
public class WavemeterChannelWidgetBase extends Composite {
	protected static String inactiveColor = "#505050";
	protected static String activeColor = "#000000";
	protected static String inRangeColor= "#007000";
	protected static String outOfRangeColor= "#800000";
	protected static String lockedBackgroundColor= "#e0e0ff";
	protected static String outOfLockBackgroundColor= "#ffe0e0";
	protected static String backgroundColor= "#ffffff";
	protected static Double OutOfLockDeviation = 0.0001;

	/**
	 *  Choice and transformation of the displayed unit.
	 */
	protected UnitListBox UnitBox;
	
	/**
	 *  The Number of the channel this widget displays.
	 */
	protected int ChannelNumber;
	
	/**
	 *  is the displayed channel active
	 */
	protected boolean Active;
	
	protected WavemeterServiceAsync WavemeterService;
	
	/**
	 *  Position of the widget in the Wavelength display FlexTable
	 */
	protected int Row, Column, ColumnSpan;
	protected Panel ErrorPanel;
	
	/**
	 * Sets the properties in the table. Stored here so the invoking
	 * class can ask back.
	 * @param row
	 * @param col
	 * @param colspan
	 */
	public void setTableProp(int row, int col, int colspan) { 
		Row = row;
		Column = col;
		ColumnSpan = colspan;
	}
	
	/**
	 * retrieve the stored row this widget will be displayed in. 
	 * @return the row
	 */
	public int getRow() { return Row; }
	
	/**
	 * 
	 * @return the column the widget is displayed in
	 */
	public int getColumn() { return Column; }
	
	/**
	 * 
	 * @return the number of columns this widget spreads
	 */
	public int getColumnSpan() { return ColumnSpan; }
	
	/**
	 * set the unit of the wavemeter display
	 * @param index
	 */
	public void setUnit(int index)
	{
		UnitBox.setSelectedIndex(index);
	}
	
	/**
	 * Update the data displayed by this widget
	 * @param data
	 */
	public void set(WavemeterChannelData data)	{
		Active = data.active;
	}
	
	/** 
	 * sets the font-size of the wavemeter display
	 * @param height
	 */
	public void setWavelengthLabelHeight(String height)	{
	}
	
	public WavemeterChannelWidgetBase(WavemeterServiceAsync service, int Number, boolean showunit,
	 Panel errorPanel )
	{
		ErrorPanel = errorPanel;
		ChannelNumber = Number;
		WavemeterService = service;
		// Inside Out Details
		UnitBox = new UnitListBox(showunit);
	}
	
	public void initialize(com.google.gwt.xml.client.Element domelement) {		
	}
		
 	public int getChannelNumber() {
		return ChannelNumber;
	}	
}